/*
* Copyright 2008 the original author or authors.
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ 

package com.vtls.oai.service;

import org.apache.commons.lang.builder.ToStringBuilder;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Session implements Serializable
{
   private Log log = LogFactory.getLog(getClass());	

   private Date date = null;
   private Date from = null;
   private Date until = null;
   private String metadataPrefix = null;
   private String set = null;
   private boolean sessionComplete = false;
   private Object memento = null;

   public Session()
   {
      this.date = new Date();
   }
   
   public Date getDate()
   {
      return this.date;
   }
   
   public void setFrom(final Date from)
   {
      this.from = from;
   }
   
   public Date getFrom()
   {
      return this.from;
   }
   
   public void setUntil(final Date until)
   {
      this.until = until;
   }
   
   public Date getUntil()
   {
      return this.until;
   }
   
   public void setMetadataPrefix(final String metadataPrefix)
   {
      this.metadataPrefix = metadataPrefix;
   }
   
   public String getMetadataPrefix()
   {
      return this.metadataPrefix;
   }
   
   public void setSet(final String set)
   {
      this.set = set;
   }
   
   public String getSet()
   {
      return this.set;
   }

   /*
   public String getResumptionToken()
   {
      if(this.isSessionComplete())
         return null;
      
      if(resumptionToken == null)
         resumptionToken = UUID.randomUUID().toString();
         
      return this.resumptionToken;
   }
   
   public void setResumptionToken(final String resumptionToken)
   {
      this.resumptionToken = resumptionToken;
   }
   */

   /* Local Methods
   ***************************************************************************/

   public void setSessionComplete(final boolean sessionComplete)
   {
      this.sessionComplete = sessionComplete;
   }
   
   public boolean getSessionComplete()
   {
      return this.sessionComplete;
   }

   public boolean isSessionComplete()
   {
      return this.sessionComplete;
   }

   public void setMemento(final Object memento)
   {
      this.memento = memento;
   }
   
   public Object getMemento()
   {
      return this.memento;
   }

   public String toString()
   {
      final ToStringBuilder builder = new ToStringBuilder(this);

      builder.append("sessionComplete", sessionComplete);
      builder.append("date", date);
      
      if(StringUtils.isNotEmpty(metadataPrefix))
         builder.append("metadataPrefix", metadataPrefix);

      if(from != null)
         builder.append("from", from);
      if(until != null)
         builder.append("until", until);

      if(StringUtils.isNotEmpty(set))
         builder.append("set", set);

      return builder.toString();
   }
}
